<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <script src="/jquery-3.3.1.min.js"></script>
</head>
<body>
<select id="select">
</select>
<button onclick="send()">禁言</button>
<script>
    if ('WebSocket' in window) {
        websocket = new WebSocket("ws://192.168.10.52:8087/websocket/admin");
    }
    else {
        alert('Not support websocket')
    }

    //连接发生错误的回调方法
    websocket.onerror = function () {
    };

    //连接成功建立的回调方法
    websocket.onopen = function (event) {
    };

    //接收到消息的回调方法
    websocket.onmessage = function (event) {
        var data = JSON.parse(event.data);
        if (data.code == 1) {

        } else {
            $("#select").html("");
            $.each(data.message, function (index, value) {
                $("#select").append("<option value='" + value + "'>" + value + "</option>");
            })
        }

    };

    //连接关闭的回调方法
    websocket.onclose = function () {
    };

    //监听窗口关闭事件，当窗口关闭时，主动去关闭websocket连接，防止连接还没断开就关闭窗口，server端会抛异常。
    window.onbeforeunload = function () {
        websocket.close();
    };

    //关闭连接
    function closeWebSocket() {
        websocket.close();
    }

    //禁言
    function send() {
        var object = {};
        object.code = "3";
        object.username = $("#select").val();
        object.message = "";
        websocket.send(JSON.stringify(object));
    }
</script>
</body>
</html>